﻿using System;
using System.Windows;
using System.Windows.Controls;
using Presentation;
using Infrastructure;

namespace WPFWeightConverterGUI
{
    public partial class MainWindow : Window, IView
    {
        TextBox [] listTBox;
        int numOfTBoxs;
        Presenter presenter;
        TxtLogger txtLogger;
        HTMLLogger htmlLogger;
       
        public MainWindow()
        {
            InitializeComponent();
             numOfTBoxs = 5;
            listTBox = new TextBox[numOfTBoxs];
            listTBox[0] = tBoxKg;
            listTBox[1] = tBoxPound;
            listTBox[2] = tBoxOunce;
            listTBox[3] = tBoxDram;
            listTBox[4] = tBoxGrain;
            txtLogger = new TxtLogger();
            htmlLogger = new HTMLLogger();
            presenter = new Presenter(this, txtLogger);
        }
        public int FromType
        {
            get { return comboBoxFromType.SelectedIndex; }
        }
        public string FromValue
        {
            get { return listTBox[comboBoxFromType.SelectedIndex].Text; }
        }
        public string FromKg
        {
            get { return tBoxKg.Text; }
        }
        public string FromPound
        {
            get { return tBoxPound.Text; }
        }
        public string FromOunce
        {
            get { return tBoxOunce.Text; }
        }
        public string FromDram
        {
            get { return tBoxDram.Text; }
        }
        public string FromGrain
        {
            get { return tBoxGrain.Text; }
        } 
        public string ToKg
        {
            set { tBoxKg.Text = value; }
        }
        public string ToPound
        {
            set { tBoxPound.Text = value; }
        }
        public string ToOunce
        {
            set { tBoxOunce.Text = value; }
        }
        public string ToDram
        {
            set { tBoxDram.Text = value; }
        }
        public string ToGrain
        {
            set { tBoxGrain.Text = value; }
        }
        public string ErrorMessage
        {
            set { if(value != "") MessageBox.Show(value); }
        }
        public bool TBoxKgReadOnly
        {
            set { tBoxKg.IsReadOnly = value; }
        }
        public bool TBoxPoundReadOnly
        {
            set { tBoxPound.IsReadOnly = value; }
        }
        public bool TBoxOunceReadOnly
        {
            set { tBoxOunce.IsReadOnly = value; }
        }
        public bool TBoxDramReadOnly
        {
            set { tBoxDram.IsReadOnly = value; }
        }
        public bool TBoxGrainReadOnly
        {
            set { tBoxGrain.IsReadOnly = value; }
        }
        public bool HTMLLoggerMenuItemChecked
        {
            get { return HTMLLoggerMenuItem.IsChecked; }
            set { HTMLLoggerMenuItem.IsChecked = value; }
        }
        public bool TxtLoggerMenuItemChecked
        {
            get { return txtLoggerMenuItem.IsChecked; }
            set { txtLoggerMenuItem.IsChecked = value; }
        }
        public event Action OnCalculateClick;
        public event Action SelectedIndexChanged;
        public event Action OnReadLogButtonClick;
        public event Action OnDeleteLogButtonClick;
        public event Action OnHTMLLoggerMenuItemClick;
        public event Action OnTxtLoggerMenuItemClick;
        public event DLogHandler LogHandler;

        private void calculateButton_Click(object sender, RoutedEventArgs e)
        {
            OnCalculateClick();
        }
        private void comboBoxFromType_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (!IsLoaded) return;
           SelectedIndexChanged();
        }
        private void MenuItem_Click_ReadLog(object sender, RoutedEventArgs e)
        {
            OnReadLogButtonClick();
        }
        private void MenuItem_Click_DeleteLog(object sender, RoutedEventArgs e)
        {
            OnDeleteLogButtonClick();
        }
        private void HTMLLoggerMenuItem_Click(object sender, RoutedEventArgs e)
        {
            OnHTMLLoggerMenuItemClick();
            LogHandler(htmlLogger);
        }
        private void txtLoggerMenuItem_Click(object sender, RoutedEventArgs e)
        {
            OnTxtLoggerMenuItemClick();
            LogHandler(txtLogger);
        }
    }
}
